package com.yzr.common.singleton;

/**
 * 单例模式
 *
 * @author yzr
 */
public class SingletonLazy {
    private static volatile SingletonLazy singletonLazy;

    private SingletonLazy() {
    }

    /**
     * double check lock
     *
     * @return 单例懒汉式
     */
    public static SingletonLazy getInstance() {
        if (singletonLazy == null) {
            synchronized (SingletonLazy.class) {
                if (singletonLazy == null) {
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    return singletonLazy = new SingletonLazy();
                }
            }
        }
        return singletonLazy;
    }
}
